package com.naiterui.ehp.bs.pharmacist.controller;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BaseExceptionCodes;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.pharmacist.service.IPharmacistCmsService;
import com.naiterui.ehp.bs.pharmacist.vo.user.QrcodeInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * @author luao
 * @date 2021/5/6 6:33 下午
 **/
@AllArgsConstructor
@RestController
@Api(tags = SwaggerTag.PHARMACIST + SwaggerTag.CMS_QRCODE)
@RequestMapping("/pharmacist/cms")
public class PharmacistCmsController {
    private final IPharmacistCmsService pharmacistCmsService;

    @ApiOperation(value = "扫码信息")
    @GetMapping("qrcode/info")
    @ApiImplicitParams({@ApiImplicitParam(name = "pharmacistId", value = "药师id", required = true, dataType = "long"),
        @ApiImplicitParam(name = "cmsId", value = "cmsId", required = true, dataType = "long"),
        @ApiImplicitParam(name = "uuid", value = "uuid", required = true, dataType = "string")})
    public QrcodeInfoVO qrcodeInfo(Long pharmacistId, Long cmsId, String uuid) throws BusinessException {
        return this.pharmacistCmsService.qrcodeInfo(pharmacistId, cmsId, uuid);
    }

    @ApiOperation(value = "绑定")
    @PostMapping("bind")
    @ApiImplicitParams({@ApiImplicitParam(name = "pharmacistId", value = "药师id", required = true, dataType = "long"),
        @ApiImplicitParam(name = "cmsId", value = "cmsId", required = true, dataType = "long"),})
    public void bind(Long pharmacistId, Long cmsId) throws BusinessException {
        if (pharmacistId == null || cmsId == null) {
            throw new BusinessException(BaseExceptionCodes.PARAM_ERROR);
        }
        this.pharmacistCmsService.bind(pharmacistId, cmsId);
    }

    @ApiOperation(value = "解绑")
    @PostMapping("untie")
    @ApiImplicitParams({@ApiImplicitParam(name = "pharmacistId", value = "药师id", required = true, dataType = "long")})
    public void untie(Long pharmacistId) throws BusinessException {
        if (pharmacistId == null) {
            throw new BusinessException(BaseExceptionCodes.PARAM_ERROR);
        }
        this.pharmacistCmsService.untie(pharmacistId);
    }
}
